//https://leetcode.cn/problems/happy-number/
package codeRandomThoughts.Test202快乐数;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public boolean isHappy(int n) {
        int sum = 0;//每个位置上数字的平方和
        int num = 0;//记录每个位置上的数字
        Set<Integer> hashSet = new HashSet<>();
        while (sum != 1) {
            sum = 0;
            while (n > 0) {
                num = n % 10;
                System.out.println(num);
                n = n / 10;
                sum += num * num;

            }
            if (!hashSet.add(sum))
                return false;
            System.out.println(sum);
            n = sum;
        }
        return true;
    }
}
